<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>

<?php
include 'header.php';
include 'menu.php';
?>
</head>
<body>
<br><br><br>
<?php

$tar = $_GET['tar'];
$gwname = $_GET['name'] or die ("why");
$restorepath = $_GET['restore'];
$gwtarpath = $_GET['gwtarpath'];
$tardate = substr($tar, 0, 8);


$tarrestorepath = $_GET['tarrestorepath']."/".$tardate;

$tardate = substr($tar, 0, 8);

//echo "$tar<br>";
//echo "$restorepath<br>";
//echo "$gwtarpath<br>";
//echo "$tarrestorepath<br>";
//echo "$tardate<br>";

if (substr($gwtarpath, -1) == "/")
{
	$tarfile = $gwtarpath.$tar;
}
else
{
	$tarfile = $gwtarpath."/".$tar;
}
$cmd = "sudo /opt/fbc/restoretar.sh $tarfile $tarrestorepath $restorepath";

$out = shell_exec($cmd) or die("Failed to execute script");

if ($out == 0)


{
	echo "success";

   $configfile = '/etc/opt/fbc/fbc.xml';
    $x = simplexml_load_file($configfile);

    foreach ($x->server as $s)
    {
        if ($s->name == $gwname)
        {
            $s->restorepath = $tarrestorepath;
            file_put_contents($configfile, $x->asXML()) or die("save failed");

        }
    }
}

else
{
    echo "Failed to set new restore path!";
}

?>
